<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Database Schema : DataMapper User Guide</title>

<style type='text/css' media='all'>@import url('../css/userguide.css');</style>
<link rel='stylesheet' type='text/css' media='all' href='../css/userguide.css' />

<meta http-equiv='expires' content='-1' />
<meta http-equiv= 'pragma' content='no-cache' />
<meta name='robots' content='all' />

</head>

<body>

<!-- START NAVIGATION -->
<div id="nav"><div id="nav_inner"></div></div>
<div id="nav2"><a name="top">&nbsp;</a><a id="nav_toggle" href="#"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
<div id="masthead">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td><h1>DataMapper</h1></td>
<td id="breadcrumb_right"><a href="toc.html">Table of Contents Page</a></td>
</tr>
</table>
</div>
<!-- END NAVIGATION -->

<!-- START BREADCRUMB -->
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td id="breadcrumb">
<a href="http://stensi.com/">DataMapper Home</a> &nbsp;&#8250;&nbsp;
<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
Database Schema
</td>
</tr>

</table>
<!-- END BREADCRUMB -->

<br clear="all" />


<!-- START CONTENT -->
<div id="content">


<h1>Database Schema</h1>

<p>Below is an example of a schema suited to DataMapper.  This is the schema to use with the included <b>Examples</b> Controller in the <a href="download.html">DataMapper Download</a> file.</p>

<p>You will need to change the Database name from <b>datamapper</b> to your Database's name.</p>

<p class="important"><strong>Important:</strong>&nbsp; Do not run this on a production server.  Run it on your testing server as it will drop the tables if they already exist.</p>

<br />

<textarea class="textarea" style="width:100%" cols="50" rows="56">
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

CREATE SCHEMA IF NOT EXISTS `datamapper` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `datamapper`;

-- -----------------------------------------------------
-- Table `datamapper`.`users`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `datamapper`.`users` ;

CREATE  TABLE IF NOT EXISTS `datamapper`.`users` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `username` VARCHAR(20) NOT NULL ,
  `password` VARCHAR(40) NOT NULL ,
  `salt` VARCHAR(32) NOT NULL ,
  `email` VARCHAR(120) NOT NULL ,
  `created` DATETIME NULL ,
  `updated` DATETIME NULL ,
  PRIMARY KEY (`id`) ,
  UNIQUE INDEX username (`username` ASC) ,
  UNIQUE INDEX email (`email` ASC) )
ENGINE = MyISAM;


-- -----------------------------------------------------
-- Table `datamapper`.`groups`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `datamapper`.`groups` ;

CREATE  TABLE IF NOT EXISTS `datamapper`.`groups` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `name` VARCHAR(20) NOT NULL ,
  PRIMARY KEY (`id`) ,
  UNIQUE INDEX name (`name` ASC) )
ENGINE = MyISAM;


-- -----------------------------------------------------
-- Table `datamapper`.`groups_users`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `datamapper`.`groups_users` ;

CREATE  TABLE IF NOT EXISTS `datamapper`.`groups_users` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `group_id` BIGINT UNSIGNED NOT NULL ,
  `user_id` BIGINT UNSIGNED NOT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX group_id (`group_id` ASC) ,
  INDEX user_id (`user_id` ASC) )
ENGINE = MyISAM;


-- -----------------------------------------------------
-- Table `datamapper`.`employees`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `datamapper`.`employees` ;

CREATE  TABLE IF NOT EXISTS `datamapper`.`employees` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `first_name` VARCHAR(40) NOT NULL ,
  `last_name` VARCHAR(40) NOT NULL ,
  `position` ENUM('Manager','Supervisor','Underling') NOT NULL DEFAULT 'Underling' ,
  PRIMARY KEY (`id`) ,
  UNIQUE INDEX name (`first_name` ASC, `last_name` ASC) )
ENGINE = MyISAM;


-- -----------------------------------------------------
-- Table `datamapper`.`managers_supervisors`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `datamapper`.`managers_supervisors` ;

CREATE  TABLE IF NOT EXISTS `datamapper`.`managers_supervisors` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `manager_id` BIGINT UNSIGNED NOT NULL ,
  `supervisor_id` BIGINT UNSIGNED NOT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX manager_id (`manager_id` ASC) ,
  INDEX supervisor_id (`supervisor_id` ASC) )
ENGINE = MyISAM;


-- -----------------------------------------------------
-- Table `datamapper`.`supervisors_underlings`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `datamapper`.`supervisors_underlings` ;

CREATE  TABLE IF NOT EXISTS `datamapper`.`supervisors_underlings` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `supervisor_id` BIGINT UNSIGNED NOT NULL ,
  `underling_id` BIGINT UNSIGNED NOT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX supervisor_id (`supervisor_id` ASC) ,
  INDEX underling_id (`underling_id` ASC) )
ENGINE = MyISAM;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
</textarea>


</div>
<!-- END CONTENT -->


<div id="footer">
<p>
Previous Topic:&nbsp;&nbsp;<a href="deletingrelations.html">Deleting Relationships</a>
&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
Next Topic:&nbsp;&nbsp;<a href="examples.html">Usage Examples</a>
</p>
<p><a href="http://stensi.com">DataMapper</a> &nbsp;&middot;&nbsp; Copyright &#169; 2008 &nbsp;&middot;&nbsp; <a href="http://stensi.com/">Simon Stenhouse</a></p>
<p><a href="http://codeigniter.com">CodeIgniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2006-2008 &nbsp;&middot;&nbsp; <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
</div>

<script type="text/javascript" src="../js/mootools.js"></script>
<script type="text/javascript" src="../js/menu.js"></script>
<script type="text/javascript">
<!--
	window.addEvent('domready', function() {

		// Create Menu
		var menu = new Menu({
			basepath: '../',
			pagepath: ''
		});

	});	
//-->
</script>
</body>
</html>